<?php
class SystemController extends Controller{
	//载入系统设置首页
	public function indexAction(){
		$title="系统设置";
		$nav=$this->getNavs();
		$include_file= 'systemset';
		$libraryinfo=$this->getFooter();
		include VIEWS_PATH."index.html";
	}
	
	//管理用户
	public function AdminUserAction(){
		$title="用户管理";
		$nav=$this->getNavs();
		$libraryinfo=$this->getFooter();
		$include_file="alluser";
		$adminmodel=new AdminModel("tb_manager");
		$users=$adminmodel->getAdmins();
		include VIEWS_PATH."index.html";
	}
	
	//添加用户
	public function addAction(){
		$title="添加管理员";
		$nav=$this->getNavs();
		$libraryinfo=$this->getFooter();
		$include_file="adduser";
		include VIEWS_PATH."index.html";
	}
	
	//接收数据并插入数据库
	public function insertAction(){
		$user['name']=$_POST['name'];
		$user['pwd']=$_POST['pwd'];
		$this->helper("input");
		$user=deepspecialchars($user);
		$authority['sysset']=isset($_POST['sysset'])?1:0;
		$authority['readerset']=isset($_POST['readerset'])?1:0;
		$authority['bookset']=isset($_POST['bookset'])?1:0;
		$authority['borrowback']=isset($_POST['borrowback'])?1:0;
		$authority['sysquery']=isset($_POST['sysquery'])?1:0;
		$adminmodel=new AdminModel("tb_manager");
		if ($adminmodel->setAdmin($user, $authority)) {
			$this->jump("index.php?c=system&a=adminuser","新建用户成功!" );
		}else {
			$this->jump("index.php?c=system&a=add","创建用户失败!请刷新后再试!" );
		}
	}
	
	//修改用户权限
	public function editAction(){
		$title="修改用户";
		$nav=$this->getNavs();
		$libraryinfo=$this->getFooter();
		$include_file="edituser";
		$id=$_GET['id']+0;
		$adminmodel=new AdminModel("view_userprivilege");
		$user=$adminmodel->getOneAdmin($id);
		include VIEWS_PATH."index.html";
	}
	
	public function updateAction(){
		$user['id']=$_POST['id']+0;
		$user['name']=$_POST['name'];
		$this->helper("input");
		$user=deepspecialchars($user);
		$authority['id']=$_POST['id']+0;
		$authority['sysset']=isset($_POST['sysset'])?1:0;
		$authority['readerset']=isset($_POST['readerset'])?1:0;
		$authority['bookset']=isset($_POST['bookset'])?1:0;
		$authority['borrowback']=isset($_POST['borrowback'])?1:0;
		$authority['sysquery']=isset($_POST['sysquery'])?1:0;
		$adminmodel=new AdminModel("tb_manager");
		if ($adminmodel->updateAdmin($user, $authority)) {
			$this->jump("index.php?c=system&a=adminuser","修改用户成功!" );
		}else {
			$this->jump("index.php?c=system&a=adminuser","修改用户权限失败!,请刷新后重试." );
		}
	}
	
	
	
	
	
	
	
	
	
	
	
}